﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Commerce.Common;
namespace CommerceForUmbraco.adminSection.commerce
{
    public partial class createCoupon : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                CouponTypeList.Items.Clear();
                CouponTypeCollection coupontypes = new CouponTypeCollection().OrderByAsc("Description").Load();
                CouponTypeList.Attributes.Add("style", "width: 350px;");
                CouponTypeList.Items.Add(new ListItem("choose", "0"));
                foreach (CouponType thisCouponType in coupontypes)
                {
                    CouponTypeList.Items.Add(new ListItem(thisCouponType.Description, thisCouponType.CouponTypeId.ToString()));
                }                
            }
        }

        protected void sbmt_Click(object sender, System.EventArgs e)
        {
            if (Page.IsValid)
            {
                string returnUrl = umbraco.presentation.create.dialogHandler_temp.Create(
                    umbraco.helper.Request("nodeType"),
                    int.Parse(CouponTypeList.SelectedValue),
                    0,
                    CouponCode.Text);

                if (returnUrl == "")
                {
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "refresh", "<script>\ntop.reloadCurrentNode();\ntop.closeModal();</script>");
                }
                else
                    Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "refresh", "<script type=\"text/javascript\">\ntop.reloadCurrentNode();\ntop.right.location.href = '" + returnUrl + "';\ntop.closeModal();</script>");
            }

        }
    }
}